﻿using AntDesign;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using YwhLib;

namespace YwhWeb.Pages.Daily
{
    public partial class Inhabitant
    {
        public YwhLib.QueryRsp<YwhLib.Inhabitant> inhabitantRsp = new YwhLib.QueryRsp<YwhLib.Inhabitant>();

        IEnumerable<YwhLib.Inhabitant> selectedRows;
        ITable table;

        int _pageIndex = 1;
        int _pageSize = 10;
        int _total = 0;


        public async Task OnChange(AntDesign.TableModels.QueryModel<YwhLib.Inhabitant> queryModel)
        {
            //Console.WriteLine(JsonSerializer.Serialize(queryModel));
        }

        bool drawerVisible = false;

        void NewDrawer()
        {
            this.editInhabitant = new YwhLib.Inhabitant();
            this.drawerVisible = true;
        }

       

        private YwhLib.Inhabitant editInhabitant = new YwhLib.Inhabitant();


        protected override async Task OnInitializedAsync()
        {
            inhabitantRsp = YwhCore.InhabitantService.List(_pageIndex, _pageSize);
            this.phaseOptions = YwhCore.PhaseService.List(1, 100).Items;
        }

        
        Room roomIdSelect = null;
        Phase phaseSelect = null;
        Building buildingSelect = null;
        Unit unitSelect = null;
        Room roomSelect = null;

        List<Phase> phaseOptions = new List<Phase>();
        List<Building> buildingOptions = new List<Building>();
        List<Unit> unitOptions = new List<Unit>();
        List<Room> roomOptions = new List<Room>();

        private void OnSelectedItemChangedHandlerRoom(Room value)
        {
            roomIdSelect = value;
        }

        private void OnSelectedItemChangedHandlerPhase(Phase value)
        {
            phaseSelect = value;
            this.buildingOptions = YwhCore.BuildingService.List(1, 100, phaseSelect.PhaseNo).Items;
        }

        //private void OnSelectedItemChangedHandlerPhase(Phase value)
        //{
        //    phaseSelect = value;
        //    this.buildingOptions = YwhCore.BuildingService.List(1, 100, phaseSelect.PhaseNo).Items;
        //}

        private void OnSelectedItemChangedHandlerBuilding(Building value)
        {
            buildingSelect = value;
            this.unitOptions = YwhCore.UnitService.List(1, 100, phaseSelect.PhaseNo, buildingSelect.BuildingNo).Items;
        }

        private void OnSelectedItemChangedHandlerUnit(Unit value)
        {
            unitSelect = value;
            this.roomOptions = YwhCore.RoomService.List(1, 100, phaseSelect.PhaseNo, buildingSelect.BuildingNo, unitSelect.UnitNo).Items;
        }


    }
}
